<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Admin
 *
 * @author lucas
 */
class Admin extends MY_Controller {

    //put your code here

    public function __construct() {
        parent::__construct();

        if ($this->site_redirect[1] != 'adm') {
            redirect(base_url('adm/login'));
        }

        if (!$this->session->userdata('usuario_id_user')) {
            redirect(base_url('adm/login/index'));
        }

        $this->parser->set_template('admin/template');

        $this->load->library('user_agent');

        $this->parser->set_js('jquery-ui-1.9.0.custom/js/jquery-ui-1.9.0.custom.min.js');
        $this->parser->set_js('js/hideshow.js');
        $this->parser->set_js('js/jquery.tablesorter.min.js');
        $this->parser->set_js('js/jquery.equalHeight.js');
        $this->parser->set_js('google-plus-buttons/jquery.tiptip.js');
        $this->parser->set_js('redactor/redactor/pt_br.js');
        $this->parser->set_js('redactor/redactor/redactor.min.js');
        $this->parser->set_js('js/geral.js');
        $this->parser->set_js('js/jquery.maskedinput.js');
        $this->parser->set_js('js/scripts.js');
        $this->parser->set_js('js/jUpload.js');

        $this->parser->set_css('jquery-ui-1.9.0.custom/css/custom-theme/jquery-ui-1.9.0.custom.min.css');
        $this->parser->set_css('google-plus-buttons/css/css3-buttons.css');
        $this->parser->set_css('google-plus-buttons/tiptip.css');
        $this->parser->set_css('redactor/redactor/redactor.css');
        $this->parser->set_css('css/layout.css');

        $this->load->language('dashboard/layout');
    }

    private function _permission_url() {
        global $RTR;
        $dir = str_replace('/controllers', '', str_replace(APPPATH . 'modules/', '', $RTR->fetch_directory())) . $RTR->fetch_class() . '/' . $RTR->fetch_method();
        $dira = str_replace('\\', '/', APPPATH);
        $dir = str_replace($dira . 'modules/', '', $dir);
        $this->load->model('usuarios/menu_model');
        $params = array();
        $params['CAMPOS'] = 'me.*, mo.title as mo_title';
        $params['AND']['me.status'] = 1;
        $params['AND']['me.url'] = $dir;
        $params['ORDERBY'] = 'mo.title, me.title';
        $params['JOIN'][] = array('TABELA' => $this->config->item('tblModulo') . ' as mo', 'AND' => 'mo.id_modulo = me.id_modulo', 'TIPO' => 'INNER',);
        pre($params);
        $b_consultar = $this->menu_model->consultar($params);
        if ($b_consultar == NULL) {
            show_error('Usuário sem permissão a está ação.', 302, 'Sem permissão');
        }
    }

}
